package com.laoyang.rabbit.schedule;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;

/**
 * @author com.yyy
 * @Date 2020-09-12 10:42
 * @Email yangyouyuhd@163.com
 */
public class ScheduleExecutorService {

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-hh HH:mm:ss");
        ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(5);
        for (int i = 10; i > 0; i--) {
            scheduledExecutorService.schedule(new Runnable() {
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    System.out.println(
                            "Work start, thread id:" + Thread.currentThread().getId() + " " + sdf.format(new Date()));
                }
            }, i, TimeUnit.SECONDS);
        }
    }

}
